//
//  AddCertificateViewController.m
//  InviteJob
//
//  Created by LangLang on 17/10/27.
//  Copyright © 2017年 Shui. All rights reserved.
//

#import "AddCertificateViewController.h"

@interface AddCertificateViewController ()

@property (nonatomic, strong) UIButton *navRightButton;

@property (weak, nonatomic) IBOutlet UITextField *strNameCertificate; //证书名称
@property (weak, nonatomic) IBOutlet UITextField *strCertificateProfessional;//证书专业
@property (weak, nonatomic) IBOutlet UITextField *strCertificateGrade;//证书等级
@property (weak, nonatomic) IBOutlet UIView *showButton;



@end

@implementation AddCertificateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = strColor(@"f6f6f6");
    // right item
    self.navRightButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
    if (_indexEdit == 1) {
        TitleView(@"持有证书")
        _showButton.hidden = NO;
        [self.navRightButton setImage:[UIImage imageNamed:@"icon_news_delete"] forState:UIControlStateNormal];
        self.navRightButton.imageEdgeInsets = UIEdgeInsetsMake(0,15, 0, -15);
        // 传值
        _strNameCertificate.text = _editNameCertificate;
        _strCertificateProfessional.text = _editCertificateProfessional;
        _strCertificateGrade.text = _editCertificateGrade;
    }else{
         TitleView(@"添加持有证书")
        [self.navRightButton setTitle:@"提交" forState:UIControlStateNormal];
        self.navRightButton.titleEdgeInsets = UIEdgeInsetsMake(0,10, 0, -10);
        self.navRightButton.titleLabel.font = [UIFont systemFontOfSize:16];
    }
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:self.navRightButton];
    self.navigationItem.rightBarButtonItem = rightItem;
    // 事件绑定
    [self.navRightButton addTarget:self action:@selector(navAction) forControlEvents:UIControlEventTouchUpInside];
    
}

-(void)navAction{
    
    if (_indexEdit == 1) {
       
        _strNameCertificate.text = @"";
        _strCertificateProfessional.text = @"";
        _strCertificateGrade.text = @"";
        __weak typeof(self) weakSelf = self;
        if (weakSelf.addCertificate) {
            weakSelf.addCertificate(_strNameCertificate.text, _strCertificateProfessional.text, _strCertificateGrade.text);
            [self.navigationController popViewControllerAnimated:YES];
        }
    }else{
        
        if (_strNameCertificate.text.length==0) {
            SHuiMBhudTextTimeStr(@"请填写证书名称");
            return;
        }
        if (_strCertificateProfessional.text.length==0) {
            SHuiMBhudTextTimeStr(@"请填写证书等级");
            return;
        }
        if (_strCertificateGrade.text.length==0) {
            SHuiMBhudTextTimeStr(@"请填写证书专业");
            return;
        }
        
        __weak typeof(self) weakSelf = self;
        if (weakSelf.addCertificate) {
            weakSelf.addCertificate(_strNameCertificate.text, _strCertificateProfessional.text, _strCertificateGrade.text);
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
    
    
    
    
    
}

- (IBAction)Save:(id)sender {
    
    if (_strNameCertificate.text.length==0) {
        SHuiMBhudTextTimeStr(@"请填写证书名称");
        return;
    }
    if (_strCertificateProfessional.text.length==0) {
        SHuiMBhudTextTimeStr(@"请填写证书等级");
        return;
    }
    if (_strCertificateGrade.text.length==0) {
        SHuiMBhudTextTimeStr(@"请填写证书专业");
        return;
    }
    
    if (_strNameCertificate.text == _editNameCertificate &&
        _strCertificateProfessional.text == _editCertificateProfessional &&
        _strCertificateGrade.text == _editCertificateGrade) {
        [self.navigationController popViewControllerAnimated:YES];
        return;
    }
    
    __weak typeof(self) weakSelf = self;
    if (weakSelf.addCertificate) {
        weakSelf.addCertificate(_strNameCertificate.text, _strCertificateProfessional.text, _strCertificateGrade.text);
        [self.navigationController popViewControllerAnimated:YES];
    }
    
}




@end
